INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/include)

# Figure out additional libraries for use with

FUNCTION(GET_LIB_NAME LIB_NAME LIB_OUT)
  STRING(FIND ${LIB_NAME} ".so" IS_SO)
  IF(NOT ${IS_SO} STREQUAL "-1")
    GET_FILENAME_COMPONENT(LIB_FILE ${LIB_NAME} NAME_WE)
  ELSE()
    SET(LIB_FILE ${LIB_NAME})
  ENDIF()
  SET(LIB_FILE "-l${LIB_FILE}")
  STRING(REPLACE "-llib" "-l" LIB_FILE ${LIB_FILE})
  SET(${LIB_OUT} ${LIB_FILE} PARENT_SCOPE)
ENDFUNCTION()

LIST(LENGTH SYSTEM_LIBS rllength)
IF(${rllength} GREATER 0)
  LIST(REMOVE_DUPLICATES SYSTEM_LIBS)
ENDIF()

FOREACH (LIB_NAME ${SYSTEM_LIBS})
  GET_LIB_NAME(${LIB_NAME} LIB_OUT)
  SET(extra_dynamic_LDFLAGS "${extra_dynamic_LDFLAGS} ${LIB_OUT}")
ENDFOREACH()
STRING(STRIP ${extra_dynamic_LDFLAGS} extra_dynamic_LDFLAGS)


IF(UNIX)
  IF(ICONV_EXTERNAL)
    SET(extra_dynamic_LDFLAGS "${extra_dynamic_LDFLAGS} ${ICONV_LIBRARIES}")
  ENDIF()
ENDIF(UNIX)

CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/mariadb_config.c.in
               ${CMAKE_CURRENT_BINARY_DIR}/mariadb_config.c @ONLY)

ADD_EXECUTABLE(mariadb_config ${CMAKE_CURRENT_BINARY_DIR}/mariadb_config.c)
TARGET_LINK_LIBRARIES(mariadb_config)

# Installation
#
INSTALL(TARGETS mariadb_config
        DESTINATION "bin")
